package com.hcc.gateway.netty.route.predicate;

import com.hcc.gateway.netty.context.GatewayExchange;
import com.hcc.gateway.netty.context.ReqContext;

import java.util.List;
import java.util.function.Predicate;

/**
 * 路径匹配处理
 *
 * @author shengjun.hu
 * @date 2021/12/29
 */
public class PathRoutePredicateProcessor implements RoutePredicateProcessor {

    @Override
    public Predicate<GatewayExchange> apply(PredicateConfig config) {
        List<String> patterns = config.getPatterns();
        return exchange -> {
            ReqContext reqContext = exchange.getReqContext();
            for (String pattern : patterns) {
                if (pattern.equals(reqContext.getUri())) {
                    return true;
                }
            }
            return false;
        };
    }

}
